package pl.edu.agh.winmon.hibernate;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "`" + Process.TABLE_NAME + "`")
public class Process implements Serializable {

	@Transient
	private static final long serialVersionUID = 801208794836974270L;

	/**
	 * Table name.
	 */
	@Transient
	public static final String TABLE_NAME = "process"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: id.
	 */
	@Transient
	public static final String PROP_ID = "id"; //$NON-NLS-1$

	/**
	 * Database column name: id;
	 */
	@Transient
	public static final String DB_ID = PROP_ID;

	/**
	 * Hibernate's annotation property: program.
	 */
	@Transient
	public static final String PROP_PROGRAM = "program"; //$NON-NLS-1$

	/**
	 * Database column name: program;
	 */
	@Transient
	public static final String DB_PROGRAM = "program_id"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: this process's statistic entries.
	 */
	@Transient
	public static final String PROP_STAT_ENTRIES = "statEntries"; //$NON-NLS-1$

	/**
	 * Hibernate's annotation property: PID.
	 */
	@Transient
	public static final String PROP_PID = "pid"; //$NON-NLS-1$

	/**
	 * Database column name: PID;
	 */
	@Transient
	public static final String DB_PID = PROP_PID;

	@Transient
	public static final String PROP_START_TIME = "startTime"; //$NON-NLS-1$

	@Transient
	public static final String DB_START_TIME = "start_time"; //$NON-NLS-1$

	/*
	 * @Transient public static final String PROP_USER_ID = "userId";
	 * //$NON-NLS-1$
	 * 
	 * @Transient public static final String DB_USER_ID = "user_id";
	 * //$NON-NLS-1$
	 * 
	 * @Transient public static final String PROP_GROUP_ID = "groupId";
	 * //$NON-NLS-1$
	 * 
	 * @Transient public static final String DB_GROUP_ID = "group_id";
	 * //$NON-NLS-1$
	 * 
	 * @Transient public static final String PROP_EFFECTIVE_USER_ID =
	 * "effectiveUserId"; //$NON-NLS-1$
	 * 
	 * @Transient public static final String DB_EFFECTIVE_USER_ID =
	 * "effective_user_id"; //$NON-NLS-1$
	 * 
	 * @Transient public static final String PROP_EFFECTIVE_GROUP_ID =
	 * "effectiveGroupId"; //$NON-NLS-1$
	 * 
	 * @Transient public static final String DB_EFFECTIVE_GROUP_ID =
	 * "effective_group_id"; //$NON-NLS-1$
	 */

	/**
	 * Id.
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = DB_ID)
	private Long id;

	/**
	 * Program related to this process.
	 */
	@ManyToOne
	@JoinColumn(name = DB_PROGRAM)
	private Program program;

	@OneToMany(mappedBy = TABLE_NAME)
	@OrderColumn(name = ProcessStatEntry.PROP_ID)
	private List<ProcessStatEntry> statEntries;

	/**
	 * PID.
	 */
	@Column(name = DB_PID)
	private Long pid;

	@Column(name = DB_START_TIME)
	private Long startTime = -1L;

	/**
	 * Returns Id.
	 * 
	 * @return Id.
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Sets Id.
	 * 
	 * @param id
	 *            Id.
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * Returns program related to this process.
	 * 
	 * @return Program related to this process.
	 */
	public Program getProgram() {
		return program;
	}

	/**
	 * Sets program related to this process.
	 * 
	 * @param program
	 *            Program related to this process.
	 */
	public void setProgram(Program program) {
		this.program = program;
	}

	public List<ProcessStatEntry> getStatEntries() {
		return statEntries;
	}

	public void setStatEntries(List<ProcessStatEntry> statEntries) {
		this.statEntries = statEntries;
	}

	/**
	 * Returns PID.
	 * 
	 * @return PID.
	 */
	public Long getPid() {
		return pid;
	}

	/**
	 * Sets PID.
	 * 
	 * @param pid
	 *            PID.
	 */
	public void setPid(Long pid) {
		this.pid = pid;
	}

	public Long getStartTime() {
		return startTime;
	}

	public void setStartTime(Long startTime) {
		this.startTime = startTime;
	}

}
